package ws.jdbc.concurrent.driver.sqlserver.tds.datastreamtypes;

import java.nio.ByteBuffer;
import ws.utils.ArrayUtil;

/**
 *
 * @author Wilson Santos, 36228 <wilson.santos@ua.pt>
 */
public class US_VARBYTE extends VariableLengthDataStream {

  public US_VARBYTE(Short length, byte[] data) {
    super(length, data);
  }

  @Override
  public byte[] getData() {
    return data;
  }

  @Override
  public String toString() {
    return ArrayUtil.toHexadecimal(data);
  }

  @Override
  public Short getLength() {
    return (Short) length;
  }

  @Override
  public byte[] getBytes() {
    return ByteBuffer.allocate(2 + data.length).putShort((Short) length).put(data).array();
  }

  @Override
  public int size() {
    return 2 + data.length;
  }
}
